package org.point.dao.impl;

import java.io.Serializable;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.point.common.dao.impl.BaseDaoImpl;
import org.point.common.util.DoPage;
import org.point.dao.CreditsBehaviorDao;
import org.point.domain.CreditsBehavior;
import org.springframework.stereotype.Repository;

/**
 * 
 * @ClassName: CreditsBehaviorDaoImpl  
 * @Description: TODO(积分行为对象实现类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午3:32:08  
 *
 */
@Repository("creditsBehaviorDao")
public class CreditsBehaviorDaoImpl extends BaseDaoImpl<CreditsBehavior, Serializable> implements CreditsBehaviorDao {

	/**
	 * 利用反射，获取mapper.xml的namespace
	 * <p>Title: </p>  
	 * <p>Description: </p>
	 */
	public CreditsBehaviorDaoImpl() {
		namespace = super.getNamespace();
	}
	
	// 根据查询积分行为对象列表
	public static final String SQLID_FINDCBFORMEM = "find_CB_For_Mem";
	public static final String SQLID_FINDCBFORMEMPAGE = "find_CB_For_Mem_Page";
	// 查询积分行为对象记录数
	public static final String SQLID_COUNTCBFORMEMPAGE = "count_CB_For_Mem_Page";
	// 新增积分行为对象记录
	public static final String SQLID_INSERTCB = "insert_cb";
	// 修改积分行为对象状态
	public static final String SQLID_UPDSTATUS = "upd_status";
	
	private static final String SQLID_SEARCHCBID = "seachCBid";
	private static final String SQLID_DELCBID = "del_cb_id";
	
	private static final String SQLID_DELCBIDS = "delCBids";
	
	private static final String SQLID_SEARCHSELECTEDINFO = "searchSeletedInfo";
	
	public List<CreditsBehavior> findCBForMem(Map<String, Object> map) {
		List<CreditsBehavior> records = getSqlSession().selectList(namespace + SQLID_FINDCBFORMEM, map);
		return records;
	}

	public List<CreditsBehavior> findCBForMem(DoPage<CreditsBehavior> page) {
		List <CreditsBehavior> records = null;
		try {
			records = getSqlSession().selectList(namespace + SQLID_FINDCBFORMEMPAGE, page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return records;
	}

	public Integer countCBForMem(DoPage<CreditsBehavior> page) {
		Integer result = getSqlSession().selectOne(namespace + SQLID_COUNTCBFORMEMPAGE, page);
		return result;
	}
	
	public Integer insertCB(CreditsBehavior record) {
		Integer result = getSqlSession().insert(namespace + SQLID_INSERTCB, record);
		return result;
	}

	public Integer upaStatus(Map<String, Object> map) {
		Integer result = getSqlSession().update(namespace + SQLID_UPDSTATUS, map);
		return result;
	}

	public CreditsBehavior searchCBid(Map<String, Object> map) {
		CreditsBehavior record = null;
		try {
			record = getSqlSession().selectOne(namespace + SQLID_SEARCHCBID, map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return record;
	}

	public Integer delCBbyId(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_DELCBID, map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public Integer delCBids(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace+SQLID_DELCBIDS, map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public List<Hashtable<Object, Object>> searchSelectedInfo() {
		List<Hashtable<Object, Object>> record = null;
		try {
			record = getSqlSession().selectList(namespace+SQLID_SEARCHSELECTEDINFO); 
		} catch (Exception e) {
			e.printStackTrace();
		}
		return record;
	}

}
